package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.util.SparseBooleanArray;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.businessmanagement.MemberEntity;
import com.sgb.kjwl.model.entity.request.MaterialFilterJson;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.model.entity.user.MaterChooseEntity;
import com.sgb.kjwl.view.ui.adapter.material.GoodsCompanyAdapter;
import com.sgb.kjwl.view.ui.adapter.material.MaterialFilterAdapter3;
import com.sgb.kjwl.view.widget.transport.MatterChooseWindow;
import com.swgk.core.customview.MaxRecyclerView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.ScaleUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 杨浩
 */
public class GoodsCompanyWindow extends BasePopWindow {
    private TextView typeview;
    private RecyclerView typeList;
    private GoodsCompanyAdapter typeAdapter;
    private List<MemberEntity> dataList;
    private FilterResultClick filterResultClick;

    public GoodsCompanyWindow(Context context) {
        super(context, DIR_RIGHT_MATCH_HEIGHT);
    }

    public interface FilterResultClick {
        void result(MemberEntity memberEntity,int position);
    }

    public void setFilterResultClick(GoodsCompanyWindow.FilterResultClick filterResultClick) {
        this.filterResultClick = filterResultClick;
    }


    @Override
    protected int popLayout() {
        return R.layout.popwin_goods_company;
    }

    public void setData(List<MemberEntity> dataList, int position) {
        this.dataList = dataList;
        typeAdapter.setDatas(dataList);
        typeAdapter.setDefItem(position);
    }

    public void setData(List<MemberEntity> dataList,String type) {
        this.dataList = dataList;
        typeAdapter.setDatas(dataList);
        if ("1".equals(type)) {
            typeview.setText("会员单位");
        } else {
            typeview.setText("成员单位");
        }
    }

    @Override
    protected void initView(PopViewHolder holder) {
        typeview = holder.getPop().findViewById(R.id.type_view);
        typeList = holder.getPop().findViewById(R.id.type_list);
        typeAdapter = new GoodsCompanyAdapter(mContext, null);
        typeAdapter.setItemSelect(true);
        typeAdapter.setDefItem(0);
        typeList.setLayoutManager(new GridLayoutManager(mContext, 3));
        typeList.setAdapter(typeAdapter);
        typeAdapter.setOnItemClick(new AdapterOnItemClick<MemberEntity>() {
            @Override
            public void onItemClick(MemberEntity memberEntity, int position) {
                if (filterResultClick != null) {
                    filterResultClick.result(memberEntity,position);
                }
                dismiss();
            }
        });
    }


    public void setDefData(int position) {
        typeAdapter.setDefItem(position);
    }
}
